﻿#include <CommonUnits/Units/Chrono.h>
#include <gtest/gtest.h>

TEST(ChronoTest, CastTest)
{
    EXPECT_EQ(CU::Femtoseconds(1), CU::Attoseconds(1e3));
    EXPECT_EQ(CU::Picoseconds(1), CU::Femtoseconds(1e3));
    EXPECT_EQ(CU::Nanoseconds(1), CU::Picoseconds(1e3));
    EXPECT_EQ(CU::Microseconds(1), CU::Nanoseconds(1e3));
    EXPECT_EQ(CU::Milliseconds(1), CU::Microseconds(1E3));
    EXPECT_EQ(CU::Seconds(1), CU::Milliseconds(1e3));
    EXPECT_EQ(CU::Seconds(60), CU::Minutes(1));
    EXPECT_EQ(CU::Minutes(60), CU::Hours(1));
    EXPECT_EQ(CU::Hours(24), CU::Days(1));
    EXPECT_EQ(CU::Days(7), CU::Weeks(1));
    EXPECT_EQ(CU::Days(365.2425), CU::Years(1));
    EXPECT_EQ(CU::Months(12), CU::Years(1));
}

TEST(ChronoTest, Literals)
{
    using namespace CU::Chrono::Literals;
    EXPECT_EQ(1.0_fs, 1e3_as);
    EXPECT_EQ(1.0_ps, 1e3_fs);
    EXPECT_EQ(1.0_ns, 1e3_ps);
    EXPECT_EQ(1.0_us, 1e3_ns);
    EXPECT_EQ(1.0_ms, 1e3_us);
    EXPECT_EQ(1.0_s, 1e3_ms);
    EXPECT_EQ(60.0_s, 1.0_min);
    EXPECT_EQ(60.0_min, 1.0_h);
}

TEST(DistanceTest, ToUnit)
{
    using namespace CU::Chrono::Literals;
    EXPECT_EQ(60.0_s, CU::Chrono::toUnit<CU::Seconds>(1, CU::Minutes::unit()));
    EXPECT_EQ(60.0_min, CU::Chrono::toUnit<CU::Minutes>(1, CU::Hours::unit()));
    EXPECT_EQ(24.0_h, CU::Chrono::toUnit<CU::Hours>(1, CU::Days::unit()));
    EXPECT_EQ(CU::Chrono::Days(7), CU::Chrono::toUnit<CU::Days>(1, CU::Weeks::unit()));
    EXPECT_EQ(CU::Days(365.2425), CU::Chrono::toUnit<CU::Days>(1, CU::Years::unit()));
    EXPECT_EQ(CU::Months(12), CU::Chrono::toUnit<CU::Months>(1, CU::Years::unit()));
    EXPECT_EQ(1E3_ms, CU::Chrono::toUnit<CU::Milliseconds>(1, CU::Seconds::unit()));
    EXPECT_EQ(1E3_us, CU::Chrono::toUnit<CU::Microseconds>(1, CU::Milliseconds::unit()));
    EXPECT_EQ(1E3_ns, CU::Chrono::toUnit<CU::Nanoseconds>(1, CU::Microseconds::unit()));
    EXPECT_EQ(1E3_ps, CU::Chrono::toUnit<CU::Picoseconds>(1, CU::Nanoseconds::unit()));
    EXPECT_EQ(1E3_fs, CU::Chrono::toUnit<CU::Femtoseconds>(1, CU::Picoseconds::unit()));
    EXPECT_EQ(1E3_as, CU::Chrono::toUnit<CU::Attoseconds>(1, CU::Femtoseconds::unit()));
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}